package com.didojoy.lameliarary.jni;

/**
 * Created by weiwei42 on 2018/1/22.
 */

public class FlameUtils {
    private int numChannels = 1;
    private int sampleRate = 16000;
    private int bitRate = 96;

    static {
        System.loadLibrary("mp3lame");
    }

    private native int initEncoder(int numChannels, int sampleRate, int bitRate, int mode, int quality);

    private native int destroyEncoder();

    private native int encodeFile(String sourcePath, String destinationPath);

    public int getNumChannels() {
        return this.numChannels;
    }

    public void setNumChannels(int numChannels) {
        this.numChannels = numChannels;
    }

    public int getSampleRate() {
        return this.sampleRate;
    }

    public void setSampleRate(int sampleRate) {
        this.sampleRate = sampleRate;
    }

    public int getBitRate() {
        return this.bitRate;
    }

    public void setBitRate(int bitRate) {
        this.bitRate = bitRate;
    }

    public FlameUtils() {

    }

    public FlameUtils(int numChannels, int sampleRate, int bitRate) {
        this.numChannels = numChannels;
        this.sampleRate = sampleRate;
        this.bitRate = bitRate;
    }

    public boolean raw2mp3(String source, String destination) {
        int initRes = this.initEncoder(this.numChannels, this.sampleRate, this.bitRate, 1, 2);
        int encodeRes = this.encodeFile(source, destination);
        int destroyRes = this.destroyEncoder();
        return initRes == 0 && encodeRes == 0 && destroyRes == 0;
    }
}
